<template>
    <div class="box2">
        <div class="title">
            <p>年龄比例</p>
            <img src="../../images/dataScreen-title.png" alt="">
        </div>
        <div class="charts" ref="charts">
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

// 获取charts节点
let charts = ref<any>()

onMounted(() => {
    // 获取charts类的实例
    let mychart = echarts.init(charts.value)
    // 设置实例配置项
    let option = {
        tooltip: {
            trigger: 'item'
        },
        legend: {
            top: 40,
            right:30,
            orient:'vertical',
            textStyle:{
                color:'#fff',
                fontSize:14
            }
        },
        series: [
            {
                name: '年龄比例',
                type: 'pie',
                radius: ['40%', '70%'],
                avoidLabelOverlap: false,
                itemStyle: {
                    borderRadius: 10,
                    borderColor: '#fff',
                    borderWidth: 2
                },
                label: {
                    show: true,
                    position: 'inside',
                    color:'#fff'
                },
                labelLine: {
                    show: false
                },
                data: [
                    { value: 1048, name: '军事' },
                    { value: 735, name: '新闻' },
                    { value: 580, name: '直播' },
                    { value: 484, name: '娱乐' },
                    { value: 300, name: '财经' }
                ]
            }
        ],
        grid: {
            left: 0,
            right: 0,
            top: 0,
            bottom: 0
        }
    };
    mychart.setOption(option)
})
</script>

<style lang="scss" scoped>
.box2 {
    width: 100%;
    height: 100%;
    background: url('../../images/dataScreen-main-cb.png') no-repeat;
    background-size: 100% 100%;

    .title {
        margin-left: 20px;

        p {
            color: #fff;
            font-size: 20px;
        }
    }

    .charts {
        height: 260px;
    }
}
</style>